package cn.iocoder.yudao.module.infrastructure.file.controller.admin.vo.file;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

@Schema(description = "管理后台 - 上传文件 Request VO")
@Data
@Valid
public class FileUploadReqVO {

    @Schema(description = "文件附件数据", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "文件附件不能为空")
    private MultipartFile file;

    @Schema(description = "附件存储目录", example = "XXX/YYY")
    private String directory;

    @SuppressWarnings("unused")
    @AssertTrue(message = "文件目录不正确")
    @JsonIgnore
    public boolean validateDirectory() {
        return !StrUtil.containsAny(directory, "..", "/", "\\");
    }

}
